package com.dinadi.yidi.ui.view;


import android.content.Context;
import android.content.Intent;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;

import com.dinadi.yidi.R;

/**
 * 无网络操作
 * */
public class NoNetwork extends LinearLayout {
	private RelativeLayout network_settings;
	private ImageView reload;
	private Context mContext;
	
	private OnClickListener onClickListener;
	
	public NoNetwork(Context context) {
		super(context);
	}

	public NoNetwork(Context context, AttributeSet attrs) {
		super(context, attrs);
		this.mContext=context;
		LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		inflater.inflate(R.layout.layout_load_failure, this);
		network_settings=(RelativeLayout) findViewById(R.id.network_settings);
		reload=(ImageView) findViewById(R.id.btn_reload);
		network_settings.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				   Intent intent =  new Intent(android.provider.Settings.ACTION_WIFI_SETTINGS);  
				   mContext.startActivity(intent);
			}
		});
		reload.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				if(onClickListener != null){
					onClickListener.onClick(v);
				}
			}
		});
	}
	
	public void setNetworkSettings(boolean isShow){
		if(isShow){
			network_settings.setVisibility(View.VISIBLE);
		}else{
			network_settings.setVisibility(View.GONE);
		}
	}
	
	public void setOnClickListener(OnClickListener onClickListener){
		this.onClickListener = onClickListener;
	}

}
